//
//  AuctionCell.swift
//  LeGou
//
//  Created by lxm on 2022/10/15.
//

import UIKit

class AuctionOrderCell: XMBaseTableViewCell {

    @IBOutlet weak var time: UILabel!
    @IBOutlet weak var dateNumContent: UIView!
    
    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var img: UIImageView!
    @IBOutlet weak var stateLabel: UILabel!
    
    @IBOutlet weak var eismateStack: UIView!
    @IBOutlet weak var eismate: UIButton!
    
    @IBOutlet weak var join: UIButton!
    
    @IBOutlet weak var info: UILabel!
    @IBOutlet weak var orderNum: UILabel!
    @IBOutlet weak var moneyBtn: UIButton!
    @IBOutlet weak var currentMoney: UILabel!
    @IBOutlet weak var dqj: UILabel!
    @IBOutlet weak var leftBtn: UIButton!
    @IBOutlet weak var dateNum: UILabel!
    @IBOutlet weak var rightBtn: UIButton!
    
    @IBOutlet weak var cj: UILabel!
    @IBOutlet weak var givePrice: UILabel!
    
    @IBOutlet weak var addvance: UIButton!
    
    @IBOutlet weak var compoundStatus: UILabel!
    
    @IBOutlet weak var endTime: UILabel!
    
    @IBOutlet weak var estH: NSLayoutConstraint!
    
    let tan = DetailShareView.TriangleView()

    var jpBtnLeftColor = "#F07650".zm.hex()
    
    var jpBtnRightColor = "#DC1927".zm.hex()
    
    var timer = Observable<Int>.timer(.seconds(0), period: .seconds(1), scheduler: MainScheduler.instance)
    
    var endDate : Date?

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        tan.direction = .down
        tan.fillColor = UIColor.zm.color(hexString: "#FFDA18")
        addSubview(tan)
        tan.snp.makeConstraints { make in
            make.top.equalTo(join.snp.bottom)
            make.centerX.equalTo(join)
            make.width.equalTo(5)
            make.height.equalTo(3.5)
        }
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        ZMUtil.clipCircle(view: dateNumContent, Corner: [.bottomRight], radius: 8)
//        moneyBtn.style.GradientLeftToRight(Top: "#FFD940".zm.hex(), Bottom: "#FF9900".zm.hex())
    }
    
    func updateDate() {
        if let endDate = endDate {
            endTime.isHidden = false
            let count = AppHelper.countTime(now: RedBagService.shared.nowTimeinterval, end: endDate.timeIntervalSince1970)
            endTime.text = String(format: "%02d:%02d:%02d", count.h, count.m, count.s)
            if count.h == 0, count.m == 0, count.s == 0 {
                rightBtn.isHidden = true
                endTime.text = "超时未支付"
            }
        } else {
            endTime.text = ""
            endTime.isHidden = true
        }
    }

    // 0 即将开始 1 竞购中 2 已结束
    func setStyle(type : Int) {
//        jpBtn.isHidden = false
//        if type == 0 {
//            // 即将开始
//            jpBtnLeftColor = "#48A1A7".zm.hex()
//            jpBtnRightColor = "#48A1A7".zm.hex()
//            jpBtn.setTitle("提醒我", for: .normal)
//            jpBtn.setImage(UIImage.init(named: "auction_clock_w"), for: .normal)
//            dqj.textColor = "#48A1A7".zm.hex()
//            currentMoney.textColor = "#48A1A7".zm.hex()
//            successIcon.isHidden = true
//        } else if type == 1 {
//            jpBtnLeftColor = "#F07650".zm.hex()
//            jpBtnRightColor = "#DC1927".zm.hex()
//            jpBtn.setTitle("竞购", for: .normal)
//            jpBtn.setImage(UIImage.init(named: "auction_hammer"), for: .normal)
//            dqj.textColor = "#DE3F26".zm.hex()
//            currentMoney.textColor = "#DE3F26".zm.hex()
//            successIcon.isHidden = true
//        } else if type == 2 {
//            jpBtnLeftColor = "#F07650".zm.hex()
//            jpBtnRightColor = "#DC1927".zm.hex()
//            jpBtn.isHidden = true
//            dqj.textColor = "#DE3F26".zm.hex()
//            currentMoney.textColor = "#DE3F26".zm.hex()
//            successIcon.isHidden = false
//        }
//        jpBtn.layoutIfNeeded()
//        layoutIfNeeded()
    }
}
